﻿using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using LunchLearn.WebApi.App_Start;
using Microsoft.AspNet.SignalR;
using Microsoft.Practices.Unity;
using System;
using System.Data.Entity;
using LunchLearn.WebApi.Repository;

namespace LunchLearn.WebApi
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class WebApiApplication : HttpApplication
    {
        private UnityContainer _container;

        protected void Application_Start()
        {
            _container = new UnityContainer();
            AreaRegistration.RegisterAllAreas();
            UnityConfig.RegisterDependencies(_container);
            UnityConfig.Register(GlobalConfiguration.Configuration, _container);
            HubConfig.Register(RouteTable.Routes, _container);
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            DurandalBundleConfig.RegisterBundles(BundleTable.Bundles);
            GlobalConfiguration.Configuration.MessageHandlers.Add(new BreezeSimpleCorsHandler());
            GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(50);

            //Enable when Local to initialize DB
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<LunchLearnContext, Configuration>());

        }
    }

}